filechooser: Test canceling the dialog inside a GtkFileChooserButton
authorFederico Mena Quintero <federico@gnome.org>
Tue, 12 Feb 2013 00:19:45 +0000 (18:19 -0600)
committerFederico Mena Quintero <federico@gnome.org>
Thu, 14 Feb 2013 00:01:39 +0000 (18:01 -0600)
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
gtk/tests/filechooser.c

index 765c1b771183ba8c0f41337e23cc95b9d91ecae4..b902ddefe77a3ede38534f07f73f78f1c6baef6f 100644 (file)
@@ -329,11 +329,59 @@ test_file_chooser_button_set_folder (void)
   gtk_widget_destroy (window);
 }
 
+static void
+test_file_chooser_button_dialog_cancel (void)
+{
+  GtkWidget *window;
+  GtkWidget *fc_dialog;
+  GtkWidget *fc_button;
+  GList *children;
+  char *filename;
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+  fc_dialog = gtk_file_chooser_dialog_new ("Select a file",
+                                          NULL,
+                                          GTK_FILE_CHOOSER_ACTION_OPEN,
+                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                          GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+                                          NULL);
+
+  fc_button = gtk_file_chooser_button_new_with_dialog (fc_dialog);
+  gtk_container_add (GTK_CONTAINER (window), fc_button);
+
+  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fc_button), FILE_NAME);
+
+  gtk_widget_show_all (window);
+  wait_for_idle ();
+
+  children = gtk_container_get_children (GTK_CONTAINER (fc_button));
+  g_assert (children && GTK_IS_BUTTON (children->data));
+  gtk_button_clicked (GTK_WIDGET (children->data));
+  g_list_free (children);
+
+  wait_for_idle ();
+
+  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fc_dialog), "/etc/group");
+  wait_for_idle ();
+
+  gtk_dialog_response (GTK_DIALOG (fc_dialog), GTK_RESPONSE_CANCEL);
+  wait_for_idle ();
+
+  filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc_button));
+  g_assert_cmpstr (filename, ==, FILE_NAME);
+
+  g_free (filename);
+  gtk_widget_destroy (window);
+  gtk_widget_destroy (fc_dialog);
+}
+
 static void
 setup_file_chooser_button_tests (void)
 {
   g_test_add_func ("/GtkFileChooserButton/set_filename", test_file_chooser_button_set_filename);
   g_test_add_func ("/GtkFileChooserButton/set_folder", test_file_chooser_button_set_folder);
+  g_test_add_func ("/GtkFileChooserButton/set_folder", test_file_chooser_button_dialog_cancel);
 }
 
 struct confirm_overwrite_closure {